package com.interview.item.javabase.arrays;

import java.util.ArrayList;
import java.util.Iterator;

/**
 * @Author:zxh
 * @Description: 设置集合中某一元素为第一个元素
 * @Date: 2020/5/22
 * @Modified By:
 */
public class ArraysSetZeroElement {
    public static void main(String[] args) {
        ArrayList<String> arrayListOne = new ArrayList<>();
        arrayListOne.add("one");
        arrayListOne.add("two");
        arrayListOne.add("three");
        arrayListOne.add("four");
        System.out.println("输出O：" + arrayListOne.toString());


        String strTo = "";
        Iterator<String> iterator = arrayListOne.iterator();
        while (iterator.hasNext()) {
            String next = iterator.next();
            if (next.equals("three")) {
                strTo = next;
                iterator.remove();
            }
        }
        arrayListOne.add(0, strTo);

        System.out.println("输出1：" + arrayListOne.toString());
    }
}
